package com.ruoyi.swla2.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.swla2.domain.BasicDma;
import com.ruoyi.swla2.service.IBasicDmaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * DMA配置Controller
 *
 * @author gdqt
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/region/basicDma")
public class BasicDmaController extends BaseController {
    @Autowired
    private IBasicDmaService basicDmaService;

    /**
     * 查询DMA配置列表
     */
    @PreAuthorize("@ss.hasPermi('region:basicDma:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicDma basicDma) {
        startPage();
        List<BasicDma> list = basicDmaService.selectBasicDmaList(basicDma);
        return getDataTable(list);
    }

    /**
     * 导出DMA配置列表
     */
    @PreAuthorize("@ss.hasPermi('region:basicDma:export')")
    @Log(title = "DMA配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicDma basicDma) {
        List<BasicDma> list = basicDmaService.selectBasicDmaList(basicDma);
        ExcelUtil<BasicDma> util = new ExcelUtil<BasicDma>(BasicDma.class);
        util.exportExcel(response, list, "DMA配置数据");
    }

    @PreAuthorize("@ss.hasPermi('region:basicDfq:query')")
    @GetMapping(value = "/getBasicDmaByAreaId")
    public AjaxResult getBasicDmaByAreaId(@RequestParam("areaId") String areaId) {
        return success(basicDmaService.getBasicDmaByAreaId(areaId));
    }

    /**
     * 获取DMA配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('region:basicDma:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID) {
        return success(basicDmaService.selectBasicDmaByID(ID));
    }

    /**
     * 新增DMA配置
     */
    @PreAuthorize("@ss.hasPermi('region:basicDma:add')")
    @Log(title = "DMA配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicDma basicDma) {
        basicDma.setTenantId(this.getTenantId());
        return toAjax(basicDmaService.insertBasicDma(basicDma));
    }

    /**
     * 修改DMA配置
     */
    @PreAuthorize("@ss.hasPermi('region:basicDma:edit')")
    @Log(title = "DMA配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicDma basicDma) {
        return toAjax(basicDmaService.updateBasicDma(basicDma));
    }

    /**
     * 删除DMA配置
     */
    @PreAuthorize("@ss.hasPermi('region:basicDma:remove')")
    @Log(title = "DMA配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs) {
        return toAjax(basicDmaService.deleteBasicDmaByIDs(IDs));
    }
}
